package com.simple.cloud.datasource;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.keygen.KeyGeneratorFactory;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import com.simple.cloud.datasource.base.MybatisKeyGen;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Configuration;

import static com.simple.cloud.core.consts.CommonCst.SQL_KEY_GEN;


/**
 * MyBatisFlexCustomizer 是 MyBatis-Flex 为了方便 SpringBoot 用户对 MyBatis-Flex 进行初始化而产生的接口。
 */

@Configuration
@ConditionalOnMissingBean(MyBatisFlexCustomizer.class)
public class MyBatisFlexConfig implements MyBatisFlexCustomizer {
    @Override
    public void customize(FlexGlobalConfig config) {
        KeyGeneratorFactory.register(SQL_KEY_GEN, new MybatisKeyGen());
    }
}
